package com.woniu.inlet.web;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.woniu.command.Command;
import com.woniu.command.equipmentCommand.AddEquipmentStopCommand;
import com.woniu.command.equipmentCommand.DeleteEquipmentStopCommand;
import com.woniu.command.equipmentCommand.UpdateEquipmentStopCommand;
import com.woniu.outlet.po.EquipmentStop;
import com.woniu.service.EquipmentStopService;
import com.woniu.util.ResponseResult;
import com.woniu.util.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "设备报停管理")
@RequestMapping("/equipment/")
public class EquipmentStopController {

    @Autowired
    private EquipmentStopService equipmentStopService;

    //查询设备报停列表
    @GetMapping("findEquipmentStops")
    @ApiOperation("查询全部设备报停信息")
    public ResponseResult<List<EquipmentStop>> findEquipmentStops() throws Exception{
        List<EquipmentStop> equipmentStops = equipmentStopService.findEquipmentStops();
        return new ResponseResult<>(equipmentStops, "OK", ResultCode.SUCCESS.getCode());
    }

    //查询设备报停(根据设备编码)
//    @GetMapping("findEquipmentStopByEquipmentNo")
//    @ApiOperation("查询设备报停信息(根据设备编码)")
    public ResponseResult<EquipmentStop> findEquipmentStopByEquipmentNo(String equipmentNo) throws Exception{
        EquipmentStop equipmentStop = equipmentStopService.findEquipmentStopByEquipmentNo(equipmentNo);
        return new ResponseResult<>(equipmentStop,"OK", ResultCode.SUCCESS.getCode());
    }

    //查询设备报停(根据设备编码)
    @GetMapping("findEquipmentStopById")
    @ApiOperation("查询设备报停信息(根据报停id)")
    public ResponseResult<EquipmentStop> findEquipmentStopById(Long id) throws Exception{
        EquipmentStop equipmentStop = equipmentStopService.findEquipmentStopById(id);
        return new ResponseResult<>(equipmentStop,"OK", ResultCode.SUCCESS.getCode());
    }

    //添加设备报停
    @PostMapping("addEquipmentStop")
    @ApiOperation("添加设备报停信息")
    @ApiOperationSupport(ignoreParameters = {"id","stopDate","stopNo","spare1","spare2","spare3"})
    public ResponseResult<String> addEquipmentStop(EquipmentStop equipmentStop){
        Command command = new AddEquipmentStopCommand();
        boolean flag = (boolean)command.excute(equipmentStop);
        if (flag){
            return new ResponseResult<>(ResultCode.SUCCESS.getCode(),"添加设备报停成功");
        }
        return new ResponseResult<>(ResultCode.EQUIPMENTSTOP_IS_EXIST.getCode(),ResultCode.EQUIPMENTSTOP_IS_EXIST.getMessage(),"添加设备报停失败");
    }

    //修改设备报停
    @PostMapping("updateEquipmentStop")
    @ApiOperation("修改设备报停信息")
    @ApiOperationSupport(ignoreParameters = {"stopDate","equipmentNo","stopNo","spare1","spare2","spare3"})
    public ResponseResult<String> updateEquipmentStop(EquipmentStop equipmentStop){
        Command command = new UpdateEquipmentStopCommand();
        boolean flag = (boolean) command.excute(equipmentStop);
        if (flag){
            return new ResponseResult<>(ResultCode.SUCCESS.getCode(),"修改设备报停成功");
        }
        return new ResponseResult<>(ResultCode.ID_IS_NOT_EXIST.getCode(),ResultCode.ID_IS_NOT_EXIST.getMessage(),"修改设备报停失败");
    }

    //删除设备报停
    @DeleteMapping("deleteEquipmentStopById")
    @ApiOperation("删除设备报停信息(根据报停id)")
    public ResponseResult<String> deleteEquipmentStopById(Long id){
        Command command = new DeleteEquipmentStopCommand();
        boolean flag = (boolean)  command.excute(id);
        if (flag){
            return new ResponseResult<>(ResultCode.SUCCESS.getCode(),"删除设备报停成功");
        }
        return new ResponseResult<>(ResultCode.ID_IS_NOT_EXIST.getCode(),ResultCode.ID_IS_NOT_EXIST.getMessage(),"删除设备报停失败");
    }


}
